package com.tgy.MyFlowable.workflow.controller;

import com.ctsi.core.auth.annotation.PreAuth;
import com.ctsi.core.common.api.Result;
import com.ctsi.workflow.dto.FlwHandleTaskDTO;
import com.ctsi.workflow.service.IFlwHandleTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * @version 1.0
 * @author: wang xiao xiang
 * @date: 2021/8/8 20:16
 */
@RestController
@AllArgsConstructor
@RequestMapping("/flow/handle-task")
@Api(tags = "工作流：办理任务")
public class FlwHandleTaskController {

    private final IFlwHandleTaskService flwHandleTaskService;

    @PreAuth
    @PostMapping("/start")
    @ApiOperation(value = "启动")
    public Result<?> start(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.start(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/submit")
    @ApiOperation(value = "提交")
    public Result<?> submit(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.submit(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public Result<?> save(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.save(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/back")
    @ApiOperation(value = "退回")
    public Result<?> back(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.back(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/turn")
    @ApiOperation(value = "转办")
    public Result<?> turn(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.turn(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/entrust")
    @ApiOperation(value = "委托")
    public Result<?> entrust(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.entrust(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/jump")
    @ApiOperation(value = "跳转")
    public Result<?> jump(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.jump(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/end")
    @ApiOperation(value = "终止")
    public Result<?> end(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.end(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/suspend")
    @ApiOperation(value = "挂起")
    public Result<?> suspend(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.suspend(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/add-sign")
    @ApiOperation(value = "加签")
    public Result<?> addSign(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.addSign(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @PostMapping("/del-sign")
    @ApiOperation(value = "减签")
    public Result<?> delSign(@RequestBody FlwHandleTaskDTO flwHandleTaskDTO) {
        flwHandleTaskService.delSign(flwHandleTaskDTO);
        return Result.condition(Boolean.TRUE);
    }

    @PreAuth
    @GetMapping("/task-data")
    @ApiOperation(value = "数据")
    public Result<?> taskData(FlwHandleTaskDTO flwHandleTaskDTO) {
        return Result.data(flwHandleTaskService.taskData(flwHandleTaskDTO));
    }
}
